#include "UniversalSerialPort.hpp"
#include "stdio.h"

#define SERIALPORT_NUMBER   6
static UniversalSerialPort * _uninversal_serial_port[SERIALPORT_NUMBER] = {nullptr};

UniversalSerialPort::UniversalSerialPort(unsigned char serial_port_number)
    : port_number(serial_port_number){}

UniversalSerialPort * UniversalSerialPort::getInstance(unsigned char serial_port_number){
    if( _uninversal_serial_port[serial_port_number] == nullptr ){
        _uninversal_serial_port[serial_port_number] = new _UniversalSerialPort(serial_port_number);
        _uninversal_serial_port[serial_port_number]->init();
    }
    return _uninversal_serial_port[serial_port_number];
}

_UniversalSerialPort::_UniversalSerialPort(unsigned char serial_port_number)
    : UniversalSerialPort(serial_port_number){}

bool _UniversalSerialPort::init(){
    switch(port_number){
        case 0 :
            printf("usart 0 init\r\n");
            break;
        case 1 :
            printf("usart 1 init\r\n");
            break;
        default:
            return false;
    }
    return true;
}

int _UniversalSerialPort::send(void *data,int length){
    switch(port_number){
        case 0 :
            printf("usart 0 send\r\n");
            break;
        case 1 :
            printf("usart 1 send\r\n");
            break;
        default:
            return 0;
    }
    return length;
}

int _UniversalSerialPort::receive(void *data){
    switch(port_number){
        case 0 :
            printf("usart 0 receive\r\n");
            break;
        case 1 :
            printf("usart 1 receive\r\n");
            break;
        default:
            return 0;
    }
    return 0;
}

